<template>
	<view class="backLook">
		<!-- 材料归还 --- 查看记录 组件 -->
		<baseInput @inputChange="inputChange" @clearInput="clearInput"></baseInput>
		
		<view class="info">
			<scroll-view class="scroll-box" scroll-y='true' @scrolltolower='scrolltolowerEx'>
				<view class="item" v-for="(item,index) in tableData" :key="index" @click="getBackInfo(item)">
					<view class="header">
						<image class="image" src="/subpackage-materials/static/project1.png" mode=""></image>
						<view class="box">
							<view class="t1">{{item.projectName}}</view>
							<view class="t2">{{item.subProjectName}}</view>
						</view>
					</view>
					<view class="item-body">
						<view class="item-nav">
							<view class="name">归还材料：</view>
							<view class="value">{{item.materialNames}}</view>
						</view>
						<view class="item-nav">
							<view class="name">归还编号：</view>
							<view class="value">{{item.code}}</view>
						</view>
						<view class="item-nav">
							<view class="name">提交时间：</view>
							<view class="value">{{item.recordCreateDatetime}}</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
		
	</view>
</template>

<script>
	import { materialReturnWarehouseGetListByLike } from "@/api/materials/materials.js"
	import { mapMutations, mapState } from "vuex"
 	import mixins from "@/utils/mixins.js"
	export default {
		name: "backLook",
 		mixins: [mixins],
		data() {
			return {
				keyword: "",
				tableData: [],
				pagination: {
					total: "",
					pageSize: 10,
					currentPage: 1,
					totalPage: 1,
				},
			}
		},
		mounted() {
			this.init()
		},
		methods: {
			...mapMutations('materials', ["setGoBackDetailItem"]),
			init(){
				this.getList()
			},
			getList(){
				if(this.pagination.total !== "" &&  this.tableData.length >0  && this.tableData.length >= this.pagination.total ){
					// uni.showToast({
					// 	icon: "none",
					// 	title: "到底了"
					// })
					return
				}
				let _query = {
					currPage: this.pagination.currentPage,
					pageSize: this.pagination.pageSize,
					params: {
						code: this.keyword,
						requestMode:'app',
					}
				}
				materialReturnWarehouseGetListByLike(_query).then(res => {
					if (res.success) {
						let list =res.result.list.map(item => ({...item, recordCreateDatetime: this.getDate2(item.recordCreateDate) }))
						list.forEach(item=>{
							if(item.projectCascade){
								item.projectName = item.projectCascade.split("/")[0] || ""
								item.subProjectName = item.projectCascade.split("/")[1] +'/'+item.projectCascade.split("/")[2] || ""
							}
						})
						this.tableData = [...this.tableData, ...list]
						console.log(this.tableData)
						this.pagination.total = res.result.total
					}
				})
			},
			inputChange(e) {
				if (e) {
					this.keyword = e
				} else {
					this.keyword = ""
				}
				// clearTimeout(this.time)
				// this.time = setTimeout(() => {
					this.pagination.currentPage = 1
					this.tableData = []
					this.getList()
				// }, 500)
			},
			clearInput() {
				this.keyword = ""
				this.pagination.currentPage = 1
				this.tableData = []
				this.getList()
			},
			scrolltolowerEx() {
				this.pagination.currentPage++
				this.getList()
			},
			getBackInfo(item){
				this.setGoBackDetailItem(item)
				uni.navigateTo({
					url: "/subpackage-materials/pages/materials/materialsGoBack/components/lookInfo"
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.backLook{
		padding-top: 20rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		.scroll-box{
 			height: 100vh;
 			padding-top: 10rpx;
 		}
		.info{
			padding-top: 34rpx;
			.item{
				width: 100%;
				height: 384rpx;
				background: linear-gradient(180deg, #FFFFFF 0%, rgba(255, 255, 255, 0) 100%);
				box-shadow: 0rpx 0rpx 34rpx 2rpx rgba(47, 128, 237, 0.1);
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				padding: 0rpx 35rpx;
				box-sizing: border-box;
				margin-bottom: 36rpx;
				
				.header{
					height: 144rpx;
					display: flex;
					align-items: center;
					border-bottom: 2rpx solid #E0E7F6;
					.image{
						width: 70rpx;
						height: 70rpx;
						margin-right: 44rpx;
						margin-left: 12rpx;
					}
					.box{
						flex: 1;
						.t1{
							font-size: 32rpx;
							font-weight: bold;
							color: #445469;
							margin-bottom: 10rpx;
							max-width: 360rpx;
							white-space: nowrap;
							overflow: hidden;
							text-overflow: ellipsis;
						}
						.t2{
							font-size: 28rpx;
							font-weight: 500;
							color: #6A819E;
							max-width: 360rpx;
							white-space: nowrap;
							overflow: hidden;
							text-overflow: ellipsis;
						}
					}
				}
				.item-body{
					font-size: 28rpx;
					font-weight: 500;
					color: #445469;
					padding-left: 10rpx;
					padding-top: 20rpx;
					.item-nav{
						display: flex;
						margin-top: 22rpx;
						.name{
							width: 140rpx;
						}
						.value{
							width: 360rpx;
							white-space:nowrap;
							overflow:hidden;
							text-overflow:ellipsis;
						}
					}
				}
			}
		}
	}
</style>
